import Vue from "vue";
import Vuex from "vuex";

import {
  getMenus, // 路由
  getuserinfo
} from "@/api/common";

Vue.use(Vuex);
export default new Vuex.Store({
  state: {
    menulist: []
  },
  getters: {},
  mutations: {
    SET_menulist: (state, data) => {
      state.menulist = data;
    },
  },
  actions: {
    // 获取当前用户的权限
    getmenuslist(context, val) {
      getMenus()
        .then(res => {
          if (res.status == 1) {
            context.commit("SET_menulist",res.data)
            localStorage.setItem(
              "MenuList",
              JSON.stringify(res.data)
            );
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    getUserinfo(context, val) {
      getuserinfo()
        .then(res => {
          if (res.status == 1) {
            localStorage.setItem(
              "userinfo",
              JSON.stringify(res.data)
            );
          } else {
            
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
  },
  modules: {},
});
